package com.ziven.common.widget.setting;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

import com.ziven.easygo.ui.AbstractEasyViewHolder;
import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public class PreferenceHolder extends AbstractEasyViewHolder<BasePreferenceItem> {

    private final PreferenceItemsFactory itemsFactory;
    private final OnPreferenceItemClickListener listener;

    public PreferenceHolder(@NonNull ViewGroup parent, int viewType,
                            @NonNull PreferenceItemsFactory factory) {
        super(parent, factory.getPreferenceItemLayoutId(viewType));
        factory.getPreferenceItemEffect(viewType).takeEffect(itemView);
        listener = factory.getPreferenceItemClickListener();
        itemsFactory = factory;
    }

    @Override
    protected void bindLayout(BasePreferenceItem data, int position) {
        itemView.setOnClickListener(v -> listener.onItemClick(data, position, v));
        itemsFactory.bindPreferenceItemLayout(this, data, position);
    }

    @NonNull
    @Override
    public ViewHelper<View> getViewHelper(@IdRes int id) {
        return super.getViewHelper(id);
    }

    @Override
    protected <T extends View> T getView(@IdRes int id) {
        return super.getView(id);
    }
}
